﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using NAnt.Core;
using NAnt.Core.Types;
using NAnt.Core.Attributes;

namespace NAntExt.Functions
{
    /// <summary>
    /// NAnt Functions for <see cref="System.String"/>.
    /// </summary>
    [FunctionSet("string", "String")]
    public class StringFunctions : FunctionSetBase
    {
        #region Public Instance Constructors

        public StringFunctions(Project project, PropertyDictionary propDict)
            : base(project, propDict)
        {
        }

        #endregion Public Instance Constructors

        /// <summary>
        /// Returns the given string trimmed of the defined trailing characters.
        /// </summary>
        /// <param name="s">input string</param>
        /// <param name="trimChars">The characters to trim from the end of the string.</param>
        /// <returns>The string <paramref name="s"/> trimmed of trailing <paramref name="trimChars"/>.</returns>
        [Function("trim-end")]
        public static string TrimEnd(string s, string trimChars)
        {
            return s.TrimEnd(trimChars.ToCharArray());
        }

        /// <summary>
        /// Returns the given string trimmed of the defined beginning characters.
        /// </summary>
        /// <param name="s">input string</param>
        /// <param name="trimChars">The characters to trim from the beginning of the string.</param>
        /// <returns>The string <paramref name="s"/> trimmed of beginning <paramref name="trimChars"/>.</returns>
        [Function("trim-start")]
        public static string TrimStart(string s, string trimChars)
        {
            return s.TrimStart(trimChars.ToCharArray());
        }

    }
}
